#include"Pirana.h"
#define Up_Speed -0.3f
CPirana::CPirana(float _x, float _y,int _width,int _height)
{
	x=_x;
	y=_y;
	vy=-0.05f;
	ybottom=y;
	ytop=y-72;
	width=_width;
	height=_height;
	isover=false;
	moveup=true;
	Pirana=new CSprite(false,0,194,width,height,1,1,0);
}
CPirana::~CPirana()
{
	if(Pirana!=NULL) delete Pirana;
}
void CPirana::Move(int time)
{
	if(y<ytop) moveup=false;
	if(moveup==false&&y>ybottom) moveup=true;
}
int CPirana::CollisionWithMario(bool is_star_man, RECT marioRect, int direction)
{
	if(isover==true) return 0;
	RECT piranaRect=getRECT();
	RECT dest;
	if(IntersectRect(&dest,&piranaRect,&marioRect))
	{
		if(is_star_man==true)
		{
			isover=true;
			return 3;
		}
		else return 2;
	}
	else return 0;
}
void CPirana::Render(LPD3DXSPRITE sprite, LPDIRECT3DTEXTURE9 image, int time,int xcamara)
{
	if(isover==false)
	{
	Move(time);
	if(moveup==true) vy=-0.05f;
	else vy=0.05f;
	y+=vy*time;
	Pirana->Next();
	Pirana->Render(sprite,image,x-xcamara,y);
	}
}
RECT CPirana::getRECT()
{
	RECT rect;
	rect.left=x;
	rect.top=y;
	rect.right=rect.left+width;
	rect.bottom=rect.top+height;
	return rect;
}